using System.Text.RegularExpressions;
using NUnit.Framework;
using ValidationFramework.Configuration;
using ValidationFramework.Extensions;

namespace ValidationFramework.Tests.Configuration
{
    [TestFixture]
    public class RegexRuleConfigReaderTest
    {

        #region Methods

        [Test]
        public void ReadConfigComplex()
        {
            const string validatorXml = "<rule validationExpression='aaaaa' errorMessage='hello' typeName='RegexRule' ruleSet='foo' regexOptions='RightToLeft'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            var rule = (RegexRule)ConfigurationService.GetRule(ruleData, typeof(string).TypeHandle);
            Assert.AreEqual("hello", rule.ErrorMessage);
            Assert.AreEqual(RegexOptions.RightToLeft, rule.RegexOptions);
            Assert.AreEqual("aaaaa", rule.ValidationExpression);

        }


        [Test]
        public void ReadConfigSimple()
        {
            const string validatorXml = "<rule validationExpression='aaaaa' typeName='RegexRule'/>";
            var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
            var rule = (RegexRule)ConfigurationService.GetRule(ruleData, typeof(string).TypeHandle);
            Assert.AreEqual("aaaaa", rule.ValidationExpression);
            Assert.AreEqual(RegexOptions.None, rule.RegexOptions);
            Assert.IsNull(rule.ErrorMessage);

        }

        #endregion


    }
}